<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../static/js/jquery-1.8.2.min.js"></script>
    <link rel="stylesheet" href="../static/css/css.css">
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>poi技术</h5>
                </div>
                <div class="ibox-content">
                    <div  class="form-horizontal">
                        <div class="alert alert-warning">
                            1、点击右侧下载模板,从第2行开始录入数据。 <a class="alert-link" href="../../excel/template.xlsx">Excel模板下载</a><br/>
                            2、excel模板中有必填项为空时，将导入失败<br/>
                        </div>
                        <div id="file-pretty">
                            <div class="form-group">
                                <div class="col-sm-6">
                                    <label class="font-noraml">选择要上传的excel文件</label>
                                    <input type="file" class="form-control" id="excel_file_id" name="excel_file">
                                </div>

                            </div>
                        </div>
                        <div class="alert alert-danger" id="show_error_info_div" style="display:none;">

                        </div>


                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4">
                                <button class="btn btn-primary" type="submit" onclick="import_template()">导入</button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>

</div>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="../../js/content.min.js?v=1.0.0"></script>
<script src="../../js/layer.js"></script>
<script src="../../js/plugins/prettyfile/bootstrap-prettyfile.js"></script>
<script src="../../js/ajaxfileupload.js"></script>

<script type="text/javascript">
    $(function(){
        $('input[type="file"]').prettyFile();
    })
    function import_template(){
        $.ajaxFileUpload({
            url:"/poi/batch_import",
            secureuri:false,
            fileElementId:'excel_file_id',
            dataType: 'jsonp',
            success: function (data, status){
                $("#excel_file_id").val(null);
                data = $.parseJSON(data.replace(/<.*?>/ig,""));
                if(data.code=='0'){
                    layer.msg("导入成功", function() {
                        $("#show_error_info_div").attr("style","display:none");
                        window.location.reload();
                    })
                }else if(data.code=='2'){
                    var ht =data.msg;
                    var strs= new Array(); //定义一数组
                    strs=ht.split("#"); //字符分割
                    var html_="";
                    for (i=0;i<strs.length ;i++ ){
                        html_+=strs[i]+'<br/>';
                    }
                    $("#show_error_info_div").html(html_);
                    $("#show_error_info_div").attr("style","");
                }
            },
            error: function(data, status, e) {
                alert("系统异常,请稍后再试!");
            }
        });
    }

    $("#excel_file_id").onclick(function(){
        $("#excel_file_id").val(null);
    })

</script>
</body>
</html>